from selenium.webdriver.common.by import By

from xinan_ui.proxy.base_page import PageHandle
from xinan_ui.tools.read_yml_xn import ReadYaml
import time
data_eles = ReadYaml(r'D:\testLi\PythonWork\xinan_ui\config\jdzapp.yml').read_yaml()['回落卖出模块']


class TjdHlmc(PageHandle):
    def __init__(self,driver):
        self.driver=driver
        super().__init__(self.driver)

    def hlmc(self,code):
        # 点击回落卖出入口
        self.click_button(data_eles[0]['回落卖出入口'])
        time.sleep(2)
        # 选择证券按钮
        self.click_button(data_eles[1]['选择证券按钮'])
        time.sleep(1)
        # 点击代码输入框
        self.click_button(data_eles[2]['代码输入框'])
        time.sleep(1)
        # 输入代码
        self.input_element(data_eles[2]['代码输入框'], code)
        time.sleep(1)
        # 选择目标代码
        self.click_button(data_eles[3]['选择目标代码'])
        time.sleep(1)
        # 输入监控价格
        self.click_button(data_eles[4]['监控价输入框'])
        time.sleep(2)
        self.driver.press_keycode(7)
        time.sleep(1)


        # 百分比输入
        self.click_button(data_eles[6]['百分比下拉选择框'])
        time.sleep(1)
        self.click_button(data_eles[7]['差价选择按钮'])
        time.sleep(1)
        self.click_button(data_eles[5]['百分比输入框'])
        time.sleep(1)
        self.driver.find_element(By.XPATH,
                                 """/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/androidx.drawerlayout.widget.DrawerLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View[1]/android.view.View[3]/android.view.View/android.view.View[3]""").click()
        time.sleep(1)
        self.click_button(data_eles[12]['键盘完成按钮'])
        time.sleep(1)
        # 向上滑动
        self.slide_up()
        time.sleep(1)

        # 点击确定按钮
        self.click_button(data_eles[8]['确定按钮'])
        time.sleep(1)
        # 点击再次确认提交按钮
        self.click_button(data_eles[9]['确认提交按钮'])
        time.sleep(1)
        # 点击前往查看按钮
        data=self.get_text(data_eles[13]['下单成功文案'])
        time.sleep(1)
        self.click_button(data_eles[10]['前往查看按钮'])
        time.sleep(1)
        # 返回上一级按钮
        self.click_button(data_eles[11]['返回上一级按钮'])
        time.sleep(1)
        return data

